<?php
namespace module\index\controller;

use app\Controller;
use app\model\Pay as Model;
// use EasyWeChat\Factory;

class Pay extends Controller
{
    /**
     * 列表.
     * 
     */
    public function index()
    {
        $result = Model::with(['info'])->withSearch(['status'], input('get.'))->paginate([
            'list_rows'=> input('get.pageSize/d', 10),
        ]);

        return json([
            'items' => $result->items(),
            'total' => $result->total()
        ]);        
    }
    /**
     * 详情.
     * 
     */
    public function read(int $id)
    {
        $model = Model::with('info')->findOrFail($id);
        return json($model->toArray());    
    }
    /**
     * 保存.
     * 
     */
    public function save()
    {
        $model = new Model;
        $model->save($this->request->post());
        return json($model->toArray());
    }
    /**
     * 更新.
     * 
     * @param int $id
     */
    public function update(int $id)
    {
        $model = Model::findOrFail($id);
        $model->save($this->request->post());
        return json($model->toArray());
    }
    /**
     * 删除.
     * 
     * @param int $id
     */
    public function del(int $id)
    {
        $model = Model::findOrFail($id);
        $model->delete();
        return json($model->toArray());
    }
}
